<?php
declare (strict_types = 1);

namespace app\admin\validate;

use think\Validate;

class User extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名'	=>	['规则1','规则2'...]
     *
     * @var array
     */	
	protected $rule = [
        'id'          => 'number',
        'username'    => 'require|length:2, 20|alpha',
        'password'    => 'require|length:6,20',
        'rid'         => 'require',
        'cid'         => 'require',
        'status'      => 'require',
    ];
    
    /**
     * 定义错误信息
     * 格式：'字段名.规则名'	=>	'错误信息'
     *
     * @var array
     */	
    protected $message = [
        'id.require'          => 'ID参数错误',
        'username.require'    => '用户名不能为空',
        'username.alpha'      => '用户名只能为字母组合',
        'username.length'        => '用户名长度为2-20',
        'password.require'    => '密码不能为空',
        'password.length'     => '密码长度为6-20',
        'rid.require'         => '请选择用户分类',
        'cid.require'         => '请选择所属教室',
        'status.require'      => '请选择用户状态',
    ];

    /**
     * 定义情景信息
     *
     * @var array
     */
    protected $scene = [
        'add'    => ['username','password', 'rid', 'status'],
        'edit'   => ['id', 'username', 'rid', 'status'],
        'uedit'  => ['id', 'username'],
        'admin'  => ['username'],
        'cadd'   => ['username','password', 'rid', 'cid', 'status'],
        'cedit'  => ['id', 'username', 'rid', 'cid', 'status'],
        'cuedit' => ['id', 'username',  'cid'],
    ];
}
